package com.aaa.three.service.impl;

import com.aaa.three.entity.Char;
import com.aaa.three.entity.Doctor;
import com.aaa.three.mapper.CharMapper;
import com.aaa.three.pojo.domain.AdminOffice;
import com.aaa.three.result.AjaxResult;
import com.aaa.three.service.CharService;
import com.aaa.three.util.QueryDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.print.Doc;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @PACKAGE_NAME: com.aaa.three.service.impl
 * @NAME: CharServiceImpl
 * @USER: Tprairie
 * @DATE: 2022/2/28
 * @PROJECT_NAME: three
 */
@Service
public class CharServiceImpl implements CharService {
    @Autowired
    private CharMapper charMapper;
    @Override
    public AjaxResult listHistogram(Doctor doctor) {
       List<AdminOffice> officeList= charMapper.getOffice();
       if(doctor.getQuerDate()==null){
           String query = QueryDate.query(0);
           doctor.setQuerDate(query);
       }
        ArrayList<Object> objects = new ArrayList<>();

        for (AdminOffice adminOffice : officeList) {
            ArrayList<Object> objects1 = new ArrayList<>();
            doctor.setId(adminOffice.getId());
            Char listChar=charMapper.getNumber(doctor);
            if(listChar==null){
                objects1.add(adminOffice.getOname());
                objects1.add(0);
                objects.add(objects1);
            }else{
                objects1.add(adminOffice.getOname());
                objects1.add(listChar.getLastnumber());
                objects.add(objects1);
            }
        }
        return AjaxResult.success(objects);
    }

    @Override
    public AjaxResult listLineChart(Doctor doctor) {
        List<AdminOffice> officeList= charMapper.getOffice();
        if(doctor.getNewYear()==null){
            String query = QueryDate.query(0);
            String substring = query.substring(0, 4);
            doctor.setNewYear(substring);
        }
        ArrayList<Char> chars = new ArrayList<>();
        for (AdminOffice adminOffice : officeList) {
            doctor.setAid(adminOffice.getId());
            ArrayList<Object> objects = new ArrayList<>();
            for (int i = 1; i <12 ; i++) {
                doctor.setId(i);
               Char listchar=charMapper.getLine(doctor);
               if(listchar==null){
                   objects.add(0);
               }else {
                   objects.add(listchar.getLastnumber());
               }
            }
            Char aChar = new Char();
            aChar.setName(adminOffice.getOname());
            aChar.setData(objects);
            chars.add(aChar);
        }
        return AjaxResult.success(chars);
    }
}
